﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.ServiceModel;
using LotroTweeter.Properties;
using Microsoft.Http;

namespace LotroTweeter.Engine
{
    public class LotroConnector : ILotroConnector
    {
        private HttpClient client;
        private string world;

        public LotroConnector()
        {
            var developerName = Settings.Default.DeveloperName;
            var APIKey = Settings.Default.APIKey;
            world = Settings.Default.World;
            var address = string.Format(@"http://data.lotro.com/{0}/{1}/", developerName, APIKey);
            client = new HttpClient(address);
        }

        public XElement GetKinRoster(string kinship)
        {
            var address = string.Format(@"guildroster/w/{0}/g/{1}/", world,kinship);
            var response = client.Get(address);
            response.EnsureStatusIsSuccessful();
            var xresponse = response.Content.ReadAsXElement();
            return xresponse;
        }

        public XElement GetCharacterData(string characterName)
        {
            var address = string.Format(@"charactersheet/w/{0}/c/{1}/", world,characterName);
            var response = client.Get(address);
            response.EnsureStatusIsSuccessful();
            var xresponse = response.Content.ReadAsXElement();
            return xresponse;
        }
    }
}
